/*---------------------------------------------------------------------------*\
License
    This file is not part of OpenFOAM but a modified version of original 
    routine distributed with OpenFOAM.

    You can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
    Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    OpenFOAM is a trademark of OpenCFD.

    See GNU General Public License at <http://www.gnu.org/licenses/>

Application
    rhoPotentialFoam

Description
    Adapted from 'potentialFoam'.
    A simple potential flow solver for generating initial fields.
    The average density is used to correct the velocity fields.

    NB: nNonOrthCorr defaults to a minimum of 3. This allows the
    system/fvSolution to be re-used without alteration.

    Copyright (C) 2006 Mark Olesen

    ATS4i reproduced here the modified code of Mark Olesen published
    somewhere in forum of cfd-online.

    This version is not endorsed by orginal authors. Use at your own risk.

\*---------------------------------------------------------------------------*/
#include "fvCFD.H"
#include "basicPsiThermo.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])
{
    argList::validOptions.insert("n", "nNonOrthCorr");
    argList::validOptions.insert("writep", "");
    argList::validOptions.insert("writephi", "");

#   include "setRootCase.H"
#   include "createTime.H"
#   include "createMesh.H"
#   include "createFields.H"
#   include "readSIMPLEControls.H"

    if (args.options().found("n"))
    {
	nNonOrthCorr = readLabel(IStringStream(args.options()["n"])());
    }
    else if (nNonOrthCorr < 3)
    {
	nNonOrthCorr = 3;	// insist on at least 3 corrections
    }

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
    Info<< "Calculating potential flow" << endl;

#   include "pEqn.H"

    // adjust for density
    U /= avgRho;

    // Force the write
    U.write();

    if (args.options().found("writep"))
    {
        p.write();
    }

    if (args.options().found("writephi"))
    {
        phi.write();
    }

    Info<< "ExecutionTime = " << runTime.elapsedCpuTime()   << " s"
        << "  ClockTime = "   << runTime.elapsedClockTime() << " s"
        << nl << endl;

    Info<< "End\n" << endl;

    return 0;
}

// ************************************************************************* //
